﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FoneBuddy.LinqModel;
using FoneBuddy.LinqData;
using FoneBuddy.LinqModel.Data;

public partial class PromotionCode_List : System.Web.UI.Page
{
    IDataRepository _dataObject = new DataRepository();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            BindData();
      
    }

    #region ItemCommand and Bound
    protected void OnItemCommand(object sender, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {
            Int32 Id = Convert.ToInt32(e.CommandArgument);
            PromotionCode pCode = new PromotionCode(_dataObject);
            pCode.Id = Id;
            pCode.Delete();
            BindData();
        }
    }
    //protected void OnItemDataBound(object sender,RepeaterItemEventArgs e)
    //{
    //    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    //    {
           
         
    //        HiddenField hdfDiscountType = e.Item.FindControl("hdfDiscountType") as HiddenField;
    //        Int32 discountType = Convert.ToInt32(hdfDiscountType.Value);
    //        Label lblDiscountType = e.Item.FindControl("lblDiscountType") as Label;
    //        Label lblAllowUser = e.Item.FindControl("lblAllowUser") as Label;

    //        if (discountType == (Int32)EnumClass.Enums.Discount.Amount)
    //            lblDiscountType.Text = lblDiscountType.Text + " Rs";
    //        if (discountType == (Int32)EnumClass.Enums.Discount.Rate)
    //            lblDiscountType.Text = lblDiscountType.Text + " %";
    //        if (discountType == (Int32)EnumClass.Enums.Discount.Month)
    //            lblDiscountType.Text = lblDiscountType.Text + " Month";

    //        if (lblAllowUser.Text == "0")
    //        {
    //            lblAllowUser.Text = "Unlimited";
    //        }
            
            
    //    }
    //}
    #endregion

    #region BindData
    private void BindData()
    {
        PromotionCode pCode = new PromotionCode(_dataObject);
        List<SP_GetAllPromotionCodeResult> pCodes = new List<SP_GetAllPromotionCodeResult>();
        pCodes = pCode.GetAll();
        rptPromotionCode.DataSource = pCodes;
        rptPromotionCode.DataBind();
    }
    #endregion
}